package com.draw.cli.gui.panel.config;

import java.awt.FlowLayout;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.draw.cli.config.ConfigManager;

public class ServerConfigPanel extends JPanel {
	private static final long serialVersionUID = -6912218738562699535L;

	private JTextField ipField;
	private JTextField portField;

	public ServerConfigPanel() {
		this.setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
		this.setBorder(BorderFactory.createTitledBorder("Serveur"));

		JPanel pan;
		
		pan = new JPanel(new FlowLayout(FlowLayout.LEFT));
		pan.add(new JLabel("IP :"));
		this.ipField = new JTextField(20);
		this.ipField.setText(ConfigManager.getInstance().getIpServer());
		pan.add(this.ipField);
		this.add(pan);

		pan = new JPanel(new FlowLayout(FlowLayout.LEFT));
		pan.add(new JLabel("Port :"));
		this.portField = new JTextField(5);
		this.portField.setText(ConfigManager.getInstance().getPortServer()+"");
		pan.add(this.portField);
		this.add(pan);
	}

	public void ok () {
		ConfigManager.getInstance().setIpServer(this.ipField.getText());
		ConfigManager.getInstance().setPortServer(new Integer(this.portField.getText()));
	}

	public void cancel () {
		this.ipField.setText(ConfigManager.getInstance().getIpServer());
		this.portField.setText(ConfigManager.getInstance().getPortServer()+"");
	}
}
